import { defineStore } from "pinia";

export const useMenuStore = defineStore("menu", {
  state: () => {
    return {
      isCollapse: false,
      selectMenu: [],
    };
  },

  actions: {
    collapseMenu(state) {
      this.isCollapse = !this.isCollapse;
    },
    addMenu(payload) {
      //判断数组中的索引 如果为-1 则说明没有该菜单 就把他添加进去
      if (this.selectMenu.findIndex((item) => item.path === payload.path) === -1 ) {
        this.selectMenu.push(payload);
      }
    },
    removeTab(payload) {
      const index = this.selectMenu.findIndex((item) => item.path === payload.path);
      if (index !== -1) {
        this.selectMenu.splice(index, 1);
      }
    },
  },
  getters: {},
});
